##############################################################################
# operation
##############################################################################

unbind C-b
# don't suspend-client
unbind-key C-z

set -g prefix2 C-f

set-option -g escape-time 50

# act like vim
setw -g mode-keys vi
bind-key h select-pane -L
bind-key j select-pane -D
bind-key k select-pane -U
bind-key l select-pane -R
bind-key -r C-h select-window -t :-
bind-key -r C-l select-window -t :+

bind -r ^k resizep -U 10 # 绑定Ctrl+k为往↑调整面板边缘10个单元格
bind -r ^j resizep -D 10 # 绑定Ctrl+j为往↓调整面板边缘10个单元格
bind -r ^h resizep -L 10 # 绑定Ctrl+h为往←调整面板边缘10个单元格
bind -r ^l resizep -R 10 # 绑定Ctrl+l为往→调整面板边缘10个单元格

bind r source-file ~/.local/etc/tmux/tmux.conf \; display-message "Config reloaded ..."

set-option -g mouse on
# setw -g mode-keys vi # 开启vi风格后，支持vi的C-d、C-u、hjkl等快捷键

# set -g mouse on
bind m setw -g mouse off \; display "Mouse OFF" 
bind M setw -g mouse on \; display "Mouse ON"

# TODO : with vim
unbind '"'
bind - splitw -v -c '#{pane_current_path}'
unbind %
bind =  splitw -h -c '#{pane_current_path}'

# set -g word-separators "<>(){}[]/'\";@*+,.-_=!£$%^&:#~?`¬|\\ "

set -g set-clipboard on

# reload SSH_AUTH_SOCK every time
set -g update-environment "SSH_AUTH_SOCK"

# increase scrollback lines
set -g history-limit 10000

bind-key C-f last-window

# windows shift
bind-key -n C-Left swap-window -t -1\; select-window -t -1
bind-key -n C-Right swap-window -t +1\; select-window -t +1

# windows select 
bind-key C-j display-popup -E "tmux list-windows | grep -v \"^$(tmux display-message -p '#S')\$\" | fzf --reverse | cut -d \":\" -f 1 | xargs tmux select-window -t"

##############################################################################
# display
##############################################################################

# for true color
set -g default-terminal "tmux-256color"
set -ga terminal-overrides ",*256col*:Tc"

# start window numbers at 1 to match keyboard order with tmux window order
set -g base-index 1
set-window-option -g pane-base-index 1
set -g focus-events on

# renumber windows sequentially after closing any of them
set -g renumber-windows on

set -g set-titles on
set -g set-titles-string '#(whoami)@#h :: [#S]'

set -g status-interval 2        # 状态栏刷新时间
set -g status-justify left      # 状态栏列表左对齐
setw -g monitor-activity on     # 非当前窗口有内容更新时在状态栏通知
setw -g automatic-rename on

# color
set-window-option -g window-status-format '#[dem]#I-#[white]#W#[fg=white,dem]'
set-window-option -g window-status-current-format '#[fg=#ffffff,bold]#I#[fg=#ffffff]-#[fg=#ffffff]#W#[fg=dim]'
# set -wg window-status-separator "│" 
set -g window-status-separator "  "
set -g status-style bg='#666666',fg='#aaaaaa'

